<template>
  <el-card>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item>
        <a href="/home" onclick="return false" @click="back">首页</a>
      </el-breadcrumb-item>
      <el-breadcrumb-item>文章管理</el-breadcrumb-item>
      <el-breadcrumb-item>新增文章</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form label-width="100px">
      <el-form-item label="文章标题：">
        <el-input placeholder="请输入文章标题" v-model="form.title"></el-input>
      </el-form-item>
      <el-form-item label="文章内容：">
        <el-input type="textarea" v-model="form.content" :autosize="{ minRows: 15, maxRows: 20}" placeholder="请输入文章内容" style="width: 60%"></el-input>
      </el-form-item>
      <el-form-item style="margin-top: 50px">
        <el-button type="primary" @click="referArtical">提交</el-button>
        <el-button @click="clear">重置</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
export default {
  name: 'New',
  data () {
    return {
      form: {
        title: '',
        content: ''
      }
    }
  },
  methods: {
    back () {
      this.$router.push('/home')
      this.$store.state.activePath = '/home'
    },
    clear () {
      this.form.title = ''
      this.form.content = ''
    },
    async referArtical () {
      const { data: res } = await this.$http.post('/artical/new', this.form)
      if (res.status !== 200) return this.$message.error('添加文章失败')
      this.$message.success('添加文章成功')
      this.clear()
    }
  }
}
</script>

<style lang="less" scoped>
.el-form{
  margin-top: 50px;
  .el-input{
    width: 60%;
  }
}
</style>
